const { BaseCommand } = require("./base");

class TruncateCommand extends BaseCommand {
    async execute() {
        const data = this.selfData;
        const content = this.content;
        let flags = data.flags || "";
        if (flags.indexOf("g") === -1) {
            flags += "g";
        }
        const _struct = data.struct;
        const reg = new RegExp(data.pattern, flags);
        let match = reg.exec(content);
        match = match?.[1];
        return match;
    }

    getRequireContent() {
        return true;
    }

    getRequiredParams() {
        return ["pattern"];
    }
}

module.exports = {
    TruncateCommand,
};
